<?php
class GoodsAction extends Action {
    private $nav = null;
    private $brand = null;
    private $attr = null;
    private $service = null;

    public function __construct() {
        parent::__construct();
        $this->nav = new NavModel();
        $this->brand = new BrandModel();
        $this->attr = new AttrModel();
        $this->service = new ServiceModel();
    }
    public function index() {
        parent::page();
        $this->tpl->assign('allGoods',$this->model->findAll());
        $this->tpl->display(SMARTY_ADMIN.'goods/show.html');
    }
    public function add() {
        if(isset($_POST['send'])) $this->model->add() ? $this->redirect->succ('?a=goods','商品新增成功!') : $this->redirect->error('系统出错，商品新增失败!');
        $this->tpl->assign('allNav',$this->nav->findAllNav());
        $this->tpl->assign('allService',$this->service->findAddGoodsService());
        $this->tpl->assign('serviceSelected',$this->service->findAddGoodsServiceSelected());
        $this->tpl->display(SMARTY_ADMIN.'goods/add.html');
    }
    public function update() {
        if(isset($_GET['id'])) {
            $bool = array(1=>'是',0=>'否');
            if(isset($_POST['send'])) $this->model->update() ? $this->redirect->succ(Tool::getPrevPage(),'修改商品成功!') : $this->redirect->error('系统出错，修改商品失败!');
            $this->tpl->assign('bool',$bool);
            $this->tpl->assign('allNav',$this->nav->findAllNav());
            $this->tpl->assign('oneGoods',$this->model->findOne());
            $this->tpl->assign('allService',$this->service->findAddGoodsService());
            $this->tpl->display(SMARTY_ADMIN.'goods/update.html');
        }
    }
    public function delete() {
        $this->model->delete() ? $this->redirect->succ(Tool::getPrevPage(),'删除商品成功!') : $this->redirect->error('系统出错，删除商品失败!');
    }
    public function getBrand() {
        $this->brand->getBrand();
    }
    public function isUp() {
        if($this->model->isUp()) $this->redirect->succ(Tool::getPrevPage());
    }
    public function getAttr() {
        $this->attr->getAttr();
    }
}


?>